<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>
<!DOCTYPE html>
<html>
<head>
	<base href="<%=path%>"/>
<meta charset="UTF-8">
<link href="jquery/bootstrap_3.3.0/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="jquery/jquery-1.11.1-min.js"></script>
<script type="text/javascript" src="jquery/bootstrap_3.3.0/js/bootstrap.min.js"></script>

<script type="text/javascript">

	//默认情况下取消和保存按钮是隐藏的
	var cancelAndSaveBtnDefault = true;
	
	$(function(){
	    //设置备注删除修改按钮，设置鼠标划入划出展现操作
        $("#remarkBody").on("mouseover",".remarkDiv",function(){
            $(this).children("div").children("div").show();
        })
        $("#remarkBody").on("mouseout",".remarkDiv",function(){
            $(this).children("div").children("div").hide();
        })
	    //页面加载完毕之后
		$("#remark").focus(function(){
			if(cancelAndSaveBtnDefault){
				//设置remarkDiv的高度为130px
				$("#remarkDiv").css("height","130px");
				//显示
				$("#cancelAndSaveBtn").show("2000");
				cancelAndSaveBtnDefault = false;
			}
		});
		
		$("#cancelBtn").click(function(){
			//显示
			$("#cancelAndSaveBtn").hide();
			//设置remarkDiv的高度为130px
			$("#remarkDiv").css("height","90px");
			cancelAndSaveBtnDefault = true;
		});
		
		$(".remarkDiv").mouseover(function(){
			$(this).children("div").children("div").show();
		});
		
		$(".remarkDiv").mouseout(function(){
			$(this).children("div").children("div").hide();
		});
		
		$(".myHref").mouseover(function(){
			$(this).children("span").css("color","red");
		});
		
		$(".myHref").mouseout(function(){
			$(this).children("span").css("color","#E6E6E6");
		});
		//页面加载完毕之后，发起ajax请求，返回备注信息
		getRemarks();
		//点击保存按钮进行市场活动备注的添加操作
		$("#saveRemarkBtn").click(function () {
            //先进行非空判断
            if ($.trim($("#remark").val())==null||$.trim($("#remark").val())==""){
                alert("备注信息不能为空");
                return;
            }
            //发起ajax请求
            $.ajax({
                url:"workbench/activityRemark/insert.do",
                type: "post",
                data: {"noteContent":$.trim($("#remark").val()),"activityId":"${requestScope.msg.activity.id}","createBy":"${sessionScope.loginUser.name}"},
                dataType: "json",
                success:function (resp) {
                    //返回结果是一个json数组{"success":boolean,"data":备注信息}
                    if (resp.success){
                    	//添加成功，清空文本域中信息
						$("#remark").val("");
                        //在备注文本域上面新添加一个div
						var html="";
						html+="<div"+resp.data.id+"' class='remarkDiv' style='height: 60px;'>"
						html+="<img title='zhangsan' src='image/user-thumbnail.png' style='width: 30px; height:30px;'>"
						html+="<div style='position: relative; top: -40px; left: 40px;' >"
						html+="<h5>"+resp.data.noteContent+"</h5>"
						html+="<font color='gray'>市场活动</font> <font color='gray'>-</font> <b>${msg.activity.name}</b> <small style='color: gray;'> "+(resp.data.createTime)+" 由"+(resp.data.createBy)+"</small>"
						html+="<div style='position: relative; left: 500px; top: -30px; height: 30px; width: 100px; display: none;'>"
						html+="<a class='myHref' href='javascript:void(0);' onclick='update(\""+resp.data.id+"\""+","+"\""+resp.data.noteContent+"\")'><span class='glyphicon glyphicon-edit' style='font-size: 20px; color: #FF0000;'></span></a>"
						html+="&nbsp;&nbsp;&nbsp;&nbsp;"
						html+="<a class='myHref' href='javascript:void(0);' onclick='remove(\""+resp.data.id+"\")'><span class='glyphicon glyphicon-remove' style='font-size: 20px; color: #FF0000;'></span></a>"
						html+="</div>"
						html+="</div>"
						html+="</div>"
						$("#remarkDiv").before(html);
                    }else{
                        //失败
                        alert("添加备注信息失败");
                    }
                }
            })

		})
		//点击更新按钮，发起更新ajax请求
		$("#updateRemarkBtn").click(function () {
			//验证更新内容是否为空
			if ($.trim($("#noteContent").val())==""||$.trim($("#noteContent").val())==null){
				alert("备注信息不能为空");
				return;
			}
			var id=$("#remarkId").val();
			$.ajax({
				url:"workbench/activityRemark/update.do",
				type:"post",
				data:{"id":id,"noteContent":$.trim($("#noteContent").val())},
				dataType:"json",
				success:function (resp) {
					//结果为真
					if (resp.success){
						//清空修改模态窗口内容
						$("#noteContent").val("");
						//关闭模态窗口
						$("#editRemarkModal").modal("hide");
						//删除旧的备注信息，重新刷新
						$(".remarkDiv").remove();
						//刷新备注信息
						getRemarks();
					}else {
						//更新失败
						alert("更新失败");
					}
				}
			})
		})
	});
	//获取备注信息
	function getRemarks() {
		$.ajax({
			url:"workbench/activityRemark/query.do",
			type:"get",
			data:{"activityId":"${msg.activity.id}"},
			dataType:"json",
			success:function (resp) {
				//拿到返回结果先进行判断
				if (resp==null){
					return;
				}
				//将返回结果进行遍历
				var html="";
				$.each(resp,function (i,n) {
					html+="<div id='"+n.id+"' class='remarkDiv' style='height: 60px;'>"
					html+="<img title='zhangsan' src='image/user-thumbnail.png' style='width: 30px; height:30px;'>"
					html+="<div style='position: relative; top: -40px; left: 40px;' >"
					html+="<h5 id='e"+n.id+"'>"+n.noteContent+"</h5>"
					html+="<font color='gray'>市场活动</font> <font color='gray'>-</font> <b>${msg.activity.name}</b> <small style='color: gray;'> "+(n.editFlag==0?n.createTime:n.editTime)+" 由"+(n.editFlag==0?n.createBy:n.editBy)+"</small>"
					html+="<div style='position: relative; left: 500px; top: -30px; height: 30px; width: 100px; display: none;'>"
					html+="<a class='myHref' href='javascript:void(0);' onclick='update(\""+n.id+"\""+","+"\""+n.noteContent+"\")'><span class='glyphicon glyphicon-edit' style='font-size: 20px; color: #FF0000;'></span></a>"
					html+="&nbsp;&nbsp;&nbsp;&nbsp;"
					html+="<a class='myHref' href='javascript:void(0);' onclick='remove(\""+n.id+"\")'><span class='glyphicon glyphicon-remove' style='font-size: 20px; color: #FF0000;'></span></a>"
					html+="</div>"
					html+="</div>"
					html+="</div>"
				})
				//遍历完成，赋给标签,给remarkDiv往上追加,
				$("#remarkDiv").before(html);
			}
		})
	}
	//备注删除操作
	function remove(id) {
        //发起ajax请求，备注删除操作
        $.ajax({
            url:"workbench/activityRemark/remove.do",
            type:"post",
            data:{"id":id},
            dataType:"json",
            success:function (resp) {
                //返回结果
                if (resp.success){
                    //返回true，删除对应的div
					$("#"+id).remove();
                }else {
                    //结果为假，删除失败
                    alert("删除失败");
                }
            }
        })
    }
    //备注更新操作
	function update(id,noteContent) {
		//打开模态窗口
		$("#editRemarkModal").modal("show");
		//将原来备注信息显示在备注框中
		$("#noteContent").val(noteContent);
		//给remarId隐藏域赋上值
		$("#remarkId").val(id);
	}
	
</script>

</head>
<body>
	
	<!-- 修改市场活动备注的模态窗口 -->
	<div class="modal fade" id="editRemarkModal" role="dialog">
		<%-- 备注的id --%>
		<input type="hidden" id="remarkId">
        <div class="modal-dialog" role="document" style="width: 40%;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">×</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">修改备注</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">
                        <div class="form-group">
                            <label for="edit-describe" class="col-sm-2 control-label">内容</label>
                            <div class="col-sm-10" style="width: 81%;">
                                <textarea class="form-control" rows="3" id="noteContent"></textarea>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="updateRemarkBtn">更新</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 修改市场活动的模态窗口 -->
	<!-- 返回按钮 -->
	<div style="position: relative; top: 35px; left: 10px;">
		<a href="javascript:void(0);" onclick="window.history.back();"><span class="glyphicon glyphicon-arrow-left" style="font-size: 20px; color: #DDDDDD"></span></a>
	</div>
	
	<!-- 大标题 -->
	<div style="position: relative; left: 40px; top: -30px;">
		<div class="page-header">
			<h3>市场活动-${msg.activity.name} <small>${msg.activity.startDate} ~ ${msg.activity.endDate}</small></h3>
			<input type="hidden" id="activityId" value="${msg.activity.id}"/>
		</div>
		<div style="position: relative; height: 50px; width: 250px;  top: -72px; left: 700px;">
			<button type="button" class="btn btn-default" data-toggle="modal" data-target="#editActivityModal"><span class="glyphicon glyphicon-edit"></span> 编辑</button>
			<button type="button" class="btn btn-danger"><span class="glyphicon glyphicon-minus"></span> 删除</button>
		</div>
	</div>
	
	<!-- 详细信息 -->
	<div style="position: relative; top: -70px;">
		<div style="position: relative; left: 40px; height: 30px;">
			<div style="width: 300px; color: gray;">所有者</div>
			<div style="width: 300px;position: relative; left: 200px; top: -20px;"><b>${msg.username}</b></div>
			<div style="width: 300px;position: relative; left: 450px; top: -40px; color: gray;">名称</div>
			<div style="width: 300px;position: relative; left: 650px; top: -60px;"><b>${msg.activity.name}</b></div>
			<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px;"></div>
			<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px; left: 450px;"></div>
		</div>

		<div style="position: relative; left: 40px; height: 30px; top: 10px;">
			<div style="width: 300px; color: gray;">开始日期</div>
			<div style="width: 300px;position: relative; left: 200px; top: -20px;"><b>${msg.activity.startDate}</b></div>
			<div style="width: 300px;position: relative; left: 450px; top: -40px; color: gray;">结束日期</div>
			<div style="width: 300px;position: relative; left: 650px; top: -60px;"><b>${msg.activity.endDate}</b></div>
			<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px;"></div>
			<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px; left: 450px;"></div>
		</div>
		<div style="position: relative; left: 40px; height: 30px; top: 20px;">
			<div style="width: 300px; color: gray;">成本</div>
			<div style="width: 300px;position: relative; left: 200px; top: -20px;"><b>${msg.activity.cost}</b></div>
			<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -20px;"></div>
		</div>
		<div style="position: relative; left: 40px; height: 30px; top: 30px;">
			<div style="width: 300px; color: gray;">创建者</div>
			<div style="width: 500px;position: relative; left: 200px; top: -20px;"><b>${msg.activity.createBy}&nbsp;&nbsp;</b><small style="font-size: 10px; color: gray;">${msg.activity.createTime}</small></div>
			<div style="height: 1px; width: 550px; background: #D5D5D5; position: relative; top: -20px;"></div>
		</div>
		<div style="position: relative; left: 40px; height: 30px; top: 40px;">
			<div style="width: 300px; color: gray;">修改者</div>
			<div style="width: 500px;position: relative; left: 200px; top: -20px;"><b>${msg.activity.editBy}&nbsp;&nbsp;</b><small style="font-size: 10px; color: gray;">${msg.activity.editTime}</small></div>
			<div style="height: 1px; width: 550px; background: #D5D5D5; position: relative; top: -20px;"></div>
		</div>
		<div style="position: relative; left: 40px; height: 30px; top: 50px;">
			<div style="width: 300px; color: gray;">描述</div>
			<div style="width: 630px;position: relative; left: 200px; top: -20px;">
				<b>
					${msg.activity.description}
				</b>
			</div>
			<div style="height: 1px; width: 850px; background: #D5D5D5; position: relative; top: -20px;"></div>
		</div>
	</div>
	
	<!-- 备注 -->
	<div style="position: relative; top: 30px; left: 40px;" id="remarkBody">
        <div class="page-header">
            <h4>备注</h4>
        </div>
		<div id="remarkDiv" style="background-color: #E6E6E6; width: 870px; height: 90px;">
			<form role="form" style="position: relative;top: 10px; left: 10px;">
				<textarea id="remark" class="form-control" style="width: 850px; resize : none;" rows="2"  placeholder="添加备注..."></textarea>
				<p id="cancelAndSaveBtn" style="position: relative;left: 737px; top: 10px; display: none;">
					<button id="cancelBtn" type="button" class="btn btn-default">取消</button>
					<button type="button" class="btn btn-primary" id="saveRemarkBtn">保存</button>
				</p>
			</form>
		</div>
	</div>
	<div style="height: 200px;"></div>
</body>
</html>